{% load static %}
<!doctype html>
<html lang="en">
<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <!-- 上述meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <!-- Bootstrap CSS -->
    <link href="{% static 'bootstrap-5.1.3/css/bootstrap.min.css' %}" rel="stylesheet">
    <link href="{% static 'login/css/login.css' %}" rel="stylesheet"/>
    <title>登录</title>
</head>
<body>
{% include 'global_header.html' with is_login=is_login %}
<div class="container login-main">
    <div class="col">
        <form class="form-login" action="/login/" method="post">

            {% if login_form.captcha.errors %}
                <div class="alert alert-warning">{{ login_form.captcha.errors }}</div>
            {% elif message %}
                <div class="alert alert-warning">{{ message }}</div>
            {% endif %}

            {% csrf_token %}
            <h3 class="text-center">欢迎登录</h3>

            <div class="form-group">
                {{ login_form.username.label_tag }}
                {{ login_form.username }}
            </div>

            <div class="form-group">
                {{ login_form.password.label_tag }}
                {{ login_form.password }}
            </div>

            <div class="form-group">
                {{ login_form.captcha.label_tag }}
                {{ login_form.captcha }}
            </div>

            <div id="form-login-bottom">
                <a href="" id="btn-reg" class="text-success">
                    <ins>新用户注册</ins>
                </a>
                <button type="submit" class="btn btn-primary float-end">登录</button>
            </div>
        </form>
    </div>
</div> <!-- /container -->


<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
{#    以下三者的引用顺序是固定的#}
<script src="{% static 'js/jquery-3.6.0.min.js' %}"></script>
<script src="{% static 'bootstrap-5.1.3/js/bootstrap.bundle.min.js' %}"></script>
<script src="{% static 'js/ribbon.js' %}"></script>
<script>
    $('.captcha').click(function () {
        $.getJSON("/captcha/refresh/", function (result) {
            $('.captcha').attr('src', result['image_url']);
            $('#id_captcha_0').val(result['key']);
        });
    }); 
</script>
</body>
</html>